import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Consumer;

public class ArrayListTest {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add(0, "zero");
        String s = list.get(0);
        System.out.println(s);
        list.set(1,"2");
        list.remove(0);
        System.out.println(s);


        System.out.println("---------------------");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        //增强for循环
        for (String obj : list) {
            System.out.println(obj);
        }
        System.out.println("---------------------");
        //迭代器
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }
        //lambda表达式本质是一个函数
//        Consumer<String> consumer = ;
//        list.forEach(str -> System.out.println(str));
        list.forEach(System.out::println);
    }
}
